{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfa000ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "646157ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([-0.1619])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "tensor([[ 0.4501, -0.8626, -0.3114]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "a=torch.randn(1)\n",
    "b=torch.randn(1,3)\n",
    "display(a,b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "00a9505e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([-0.0729,  0.1396,  0.0504])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.matmul(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "34b9a79a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[-1.1246,  1.3846,  0.6606]], requires_grad=True)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.randn(1,3,requires_grad=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "39560d09",
   "metadata": {},
   "outputs": [],
   "source": [
    "s2 = np.array([ 0.0482, -0.4902,  1.4331])  *(-0.9728)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "2a079ab4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.04688896,  0.47686657, -1.3941197 ], dtype=float32)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.astype(np.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5d13d356",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[-0.875], [-0.0066]]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s=[[-0.8750],  [-0.0066]]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "b076ec38",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5328223649999999"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum((np.array(s)-np.array([[ 0.1573],[-0.0054]]))**2)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "02aa7c6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.0323],\n",
       "       [-0.0012]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(s)-np.array([[ 0.1573],[-0.0054]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c47e004f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.59119821"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-1.0323*0.5727"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "ee96dba3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.0006920399999999999"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-0.0012*0.5767"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "5b097f82",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.6148837500000001"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-1.0323*0.5953 + -0.0012*0.2963"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64d75286",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch_py38",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.7rc1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
